package com.bdqn.controller;

import com.bdqn.pojo.Menu;
import com.bdqn.pojo.Role;
import com.bdqn.pojo.User;
import com.bdqn.service.RoleService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.swing.plaf.PanelUI;
import java.util.List;

@RestController
@CrossOrigin //允许跨域
@RequestMapping("/role")
public class RoleController {
    @Autowired
    RoleService roleService;

    @GetMapping("/getRoles")
    public List<Role> getRoles(){
        List<Role> list=roleService.getAll();
        return list;
    }

    @GetMapping("/getUserRids")
    public List<Integer> getUserRids(int uid){
        List<Integer> list=roleService.getRids(uid);
        return list;
    }

    @GetMapping("/getPageRoles")
    public PageInfo<Role> getPageRoles(int pageNum,int pageSize,String rname){
        PageInfo<Role> pageInfo=roleService.selectPage(pageNum,pageSize,rname);
        return pageInfo;
    }

    @PostMapping("/addRole")
    public int addRole(@RequestBody Role role){
        int row=roleService.addRole(role);
        return row;
    }

    @GetMapping("/selectById")
    public Role selectById(int id){
        Role role=roleService.selectById(id);
        return role;
    }

    @PostMapping("/updateRole")
    public int updateRole(@RequestBody Role role){
        int row=roleService.updateRole(role);
        return row;
    }

    @GetMapping("/deleteRole")
    public int deleteRole(int id){
        int row=roleService.deleteRole(id);
        return row;
    }

    @GetMapping("/getMidsMenus")
    public List<Integer> getMidsMenus(int rid){
        List<Integer> list=roleService.getMidsMenus(rid);
        return list;
    }

    @GetMapping("/addRoleMenu")
    public int addRoleMenu(int rid,@RequestParam("mids") List<Integer> mids){
        int row=roleService.addRoleMenus(rid,mids);
        return row;
    }
}
